package com.personnel.schedule;

import com.personnel.mapper.LaborContractMapper;
import com.personnel.pojo.LaborContract;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
import java.util.Objects;

/**
 * @Author: YuePeng
 * @Date: 2022/4/1 9:53
 * @Version: 1.0
 */
@Component
public class LaborContractSchedule {
    @Resource
    private LaborContractMapper laborContractMapper;
    //每一小时执行一次
    @Scheduled(fixedRate = 10000)
//    @Scheduled(fixedRate = 3600000)
    public void selectApproachFailureTime() throws IOException {
        HttpClient httpClient = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet("http://127.0.0.1:8888/laborContract/selectAll");
        //3.执行请求
        HttpResponse httpResponse = httpClient.execute(httpGet);
        //4 判断请求是否成功
        int status = httpResponse.getStatusLine().getStatusCode();

        if (status == 200) {
            //读取响应内容
            String result= EntityUtils.toString(httpResponse.getEntity(), "UTF-8");
            System.out.println("result:  "+result);
        }
    }
}
